package cn.frank.framework.king.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Slf4j
public class ServletUtil {

/**
 * 获取当前线程绑定的HttpServletRequest对象。
 * @return 当前线程绑定的HttpServletRequest对象，如果不存在则返回null。
 */
public static HttpServletRequest getHttpServletRequest() {
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        if (requestAttributes == null) {
        return null;
        }

        return ((ServletRequestAttributes) requestAttributes).getRequest();
        }

}